//package com.neuedu.hisadmin.service.impl;
//
//import com.neuedu.hisadmin.entity.Rule;
//import com.neuedu.hisadmin.mapper.RuleMapper;
//import com.neuedu.hisadmin.service.IRuleService;
//import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
//import org.springframework.stereotype.Service;
//
///**
// * <p>
// *  服务实现类
// * </p>
// *
// * @author jaun
// * @since 2025-07-05
// */
//@Service
//public class RuleServiceImpl extends ServiceImpl<RuleMapper, Rule> implements IRuleService {
//
//}


package com.neuedu.hisadmin.service.impl;

import com.neuedu.hisadmin.entity.Rule;
import com.neuedu.hisadmin.mapper.RuleMapper;
import com.neuedu.hisadmin.service.IRuleService;
import com.neuedu.hisadmin.dto.RuleDTO;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
public class  RuleServiceImpl extends ServiceImpl<RuleMapper, Rule> implements IRuleService {

    @Override
    public List<RuleDTO> getRuleWithRelations() {
        return baseMapper.getRuleWithRelations();
    }


    @Override
    public List<RuleDTO> getRuleWithRelationsByCondition(String deptName, String doctorName, String ruleName) {
        // 处理空值（前端可能传空，此时查全部）
        deptName = deptName == null ? "%" : "%" + deptName + "%";
        doctorName = doctorName == null ? "%" : "%" + doctorName + "%";
        ruleName = ruleName == null ? "%" : "%" + ruleName + "%";

        return baseMapper.getRuleWithRelationsByCondition(deptName, doctorName, ruleName);
    }

    // 新增方法实现
    @Transactional // 事务控制
    @Override
    public boolean saveRule(Rule rule) {
        // 调用 MyBatis-Plus 自带的 save 方法
        return save(rule);
    }
}

